package com.bawei.week.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import com.bawei.lib_base.entity.VisitBeanItem
import com.bawei.week.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class VisitAdapter : BaseQuickAdapter<VisitBeanItem,BaseViewHolder>(R.layout.item_visit){
    override fun convert(helper: BaseViewHolder, item: VisitBeanItem) {
        helper.setText(R.id.visit_appointmentTime,item.appointmentTime)
        helper.setText(R.id.visit_visitorName,item.visitorName)
        helper.setText(R.id.visit_phoneNumber,item.phoneNumber)
        helper.setText(R.id.visit_purpose,"来访事由:${item.purpose}")
        helper.setText(R.id.visit_employeeId,"访问对象:${item.employeeId}")

        val tv_isPark = helper.getView<TextView>(R.id.visit_requestParking)
        val iv_car = helper.getView<ImageView>(R.id.iv_visit_car)
        if (item.requestParking){
            tv_isPark.apply {
                text = "已申请车位"
                setTextColor(Color.BLUE)
            }
            iv_car.setImageResource(R.drawable.ic_directions_car)
        }else{
            tv_isPark.apply {
                text = "未申请车位"
                setTextColor(Color.LTGRAY)
            }
            iv_car.setImageResource(R.drawable.ic_directions_nor_car)
        }

        val status = helper.getView<TextView>(R.id.visit_status)
        status.text = item.visitStatus
        if (item.visitStatus == "待审核"){
            status.setBackgroundResource(R.drawable.shape_spare)
            status.setTextColor(Color.GREEN)
        }else if (item.visitStatus == "已通过"){
            status.setBackgroundResource(R.drawable.shape_occupied)
            status.setTextColor(Color.BLUE)
        }else{
            status.setBackgroundResource(R.drawable.shape_under_repair)
            status.setTextColor(Color.DKGRAY)
        }
    }
}